/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.chenweihuacwh.dao.baseData;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.javaeye.chenweihuacwh.dto.baseData.MaterialsCategory;

public class MaterialsCategoryDAOHibernate extends HibernateDaoSupport  implements MaterialsCategoryDAO {

	@Override
	public MaterialsCategory getCategory(int id) {
		return (MaterialsCategory)getHibernateTemplate().get(MaterialsCategory.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<MaterialsCategory> getCategorys(int parentId) {
		return getHibernateTemplate().find("from MaterialsCategory c where c.parentId=?", parentId);
	}

	@Override
	public void removeCategory(int id) {
		Object o = getHibernateTemplate().load(MaterialsCategory.class, id);
		getHibernateTemplate().delete(o);
	}

	@Override
	public void saveCategory(MaterialsCategory category) {
		getHibernateTemplate().saveOrUpdate(category);
		logger.debug("MaterialsCategory id set to: " + category.getId());
	}
}
